angular.module('mamApp').controller('logController', ['$scope', '$state', '$uibModal', 'SystemManager','ImsDialog','AuthManager',
    function ($scope, $state, $uibModal, SystemManager,ImsDialog,AuthManager) {

        $scope.categories=[
            {key:"",value:"选择对象"},
            {key:81,value:$scope.table[81]},
            {key:82,value:$scope.table[82]},
            {key:83,value:$scope.table[83]},
            {key:89,value:$scope.table[89]},
            {key:80,value:$scope.table[80]},
            {key:79,value:$scope.table[79]},
            {key:78,value:$scope.table[78]},
            {key:84,value:$scope.table[84]},
            {key:85,value:$scope.table[85]},
            {key:86,value:$scope.table[86]},
            {key:87,value:$scope.table[87]},
            {key:88,value:$scope.table[88]}

        ]

        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            adminId: $state.params.adminId?parseInt($state.params.adminId) : "",
            category: $state.params.category?parseInt($state.params.category) : "",
            startTime: $state.params.startTime||null,
            endTime: $state.params.endTime||null,
            categoryId: $state.params.categoryId
        };

        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }

        $scope.categoryId = $scope.search.categoryId;
        $scope.searchClick = function (categoryId) {
            $scope.search.pageNo=1;
            $scope.search.categoryId = categoryId;
            $state.go($state.current.name, $scope.search)

        };

        $scope.categoryChange=function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name,$scope.search)

        }
        $scope.noPermission=false;
        SystemManager.logList([$scope.search.pageNo,$scope.search.pageSize],$scope.search).then(function (result) {
            if(result.data.c=="n"){
                $scope.noPermission=true;
            }else{
                $scope.noPermission=false;
                $scope.logList =result.data.pageList;
                $scope.logList.forEach(function(data){
                    data.title=[];
                    if(data.notes.length!=""){
                        for(var i=0,j=1;i<data.notes.length;i++,j++){
                            if(j==15){
                                data.title.push("\n");
                                j=0;
                                i--;
                            }else{
                                data.title.push(data.notes[i]);
                            }

                        }
                    }

                    data.title=data.title.join("");
                });
                $scope.paginationConf.totalItems=result.data.total;
            }

        })

        AuthManager.adminList().then(function (result) {
            $scope.adminList = $scope.adminList.concat(result.data.pageList);
        });


        $scope.adminList = [{adminId: "", fullName: "审核人"}];

        $scope.rangeDate = {
            startDate:$scope.search.startTime ? moment($scope.search.startTime).format('X'):null,
            endDate:$scope.search.endTime? moment($scope.search.endTime).format('X'):null,
            onSelected: function (data, scope) {  //时间选择确认事件
                $scope.search.startTime=data.startDate?moment(new Date(parseFloat(data.startDate)*1000)).format("YYYY-MM-DD"):null;
                $scope.search.endTime=data.endDate?moment(new Date(new Date(parseFloat(data.endDate)*1000))).format("YYYY-MM-DD"):null;
                $scope.search.pageNo=1;
                $state.go($state.current.name,$scope.search);

            }
        };


        $scope.selectChange=function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name,$scope.search);
        }

        $scope.keyup=function (e,categoryId) {

            if(e.key=="Enter"){
                $scope.search.pageNo=1;
                $scope.search.categoryId = categoryId;
                $state.go($state.current.name, $scope.search)
            }
        }


    }])

